package com.fqgj.xjd.user.integration.ocr;

import org.apache.http.HttpEntity;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;

import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

/**
 * ·
 *
 * @author liuming
 * Created on 下午3:58 2018/9/11.
 */
public class OcrHttpPost {
    private static final String appid = "11";//替换为您的账户
    private static final String appkey = "11";//替换为您的api密码
    private static final String host = "https://docs.hyperverge.co/v1-1/readPAN";

    public static String post(String url1) throws IOException {
        String responseJson = null;
        HttpClientBuilder builder = HttpClientBuilder.create();
        CloseableHttpClient client = builder.build();

        HttpPost post = new HttpPost("https://docs.hyperverge.co/v1-1/readKYC");
        post.addHeader("content-type", "multipart/form-data;");
        post.addHeader("appid", "11");
        post.addHeader("appkey", "11");

        //MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
        //multipartEntityBuilder.addTextBody("url", "11");
        StringEntity stringEntity = new StringEntity("url=11");
        post.setEntity(stringEntity);

        CloseableHttpResponse response = null;
        try {
            response = client.execute(post);
            HttpEntity entity = response.getEntity();
            responseJson = EntityUtils.toString(entity, "utf8");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (response != null) {
                try {
                    response.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return responseJson;
    }
}
